setwd("../../") ## replication directory
(rep.dir <- getwd())

so <- "dgirt_output_170608_1936-2014_social_varyingitems_states_sample"
eo <- "dgirt_output_170608_1936-2014_economic_varyingitems_states_sample"

### Read
setwd(paste0(rep.dir, "/input-data/subsampled"))
social.opinion.samples <- mget(load(paste0(so, ".RData")))
economic.opinion.samples <- mget(load(paste0(eo, ".RData")))

### Transform
social.opinion.samples.df <- as.data.frame(social.opinion.samples$dgirt_out)
economic.opinion.samples.df <- as.data.frame(economic.opinion.samples$dgirt_out)

## Write
setwd(paste0(rep.dir, "/intermediate-data/subsampled"))
foreign::write.dta(social.opinion.samples.df, paste0(so, ".dta"))
foreign::write.dta(economic.opinion.samples.df, paste0(eo, ".dta"))

q()
